package com.example.androidcomplete0102.ch15;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;

import com.example.androidcomplete0102.R;

public class DrawUnitView extends View {

		public DrawUnitView(Context context, AttributeSet attrs) {
			super(context, attrs);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			Paint Pnt = new Paint();
			Pnt.setColor(Color.YELLOW);
			Resources res = getResources();
			int width, height;
			int y = 0;
			
			DisplayMetrics dm = res.getDisplayMetrics();
			width = (int)(160 *dm.density);
			height = (int)(60 *dm.density);
			canvas.drawRect(0, y, width, y+height, Pnt);
			y += (height * 1.2f);
			
			width = (int)res.getDimension(R.dimen.drawunit_width);
			height = (int)res.getDimension(R.dimen.drawunit_height);
			canvas.drawRect(0,  y, width, y+height, Pnt);
			y += (height * 1.2f);
			
			width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, dm);
			height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60, dm);
			canvas.drawRect(0, y, width, y+height, Pnt);
			y += (height * 1.2f);
		}
}
